package com.gimi.cloud.jimi.dao.dao.order;


import com.gimi.cloud.jimi.dao.dao.sys.BaseDao;
import com.gimi.cloud.jimi.dao.myMapper.MyMapper;
import com.gimi.cloud.jimi.dto.order.ReplantDTO;
import com.gimi.cloud.jimi.entity.order.ReplantEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ReplantDao extends MyMapper<ReplantEntity>, BaseDao<ReplantEntity, ReplantDTO> {

    @Select("SELECT \n" +
            "rep.PLANTID as plantid,\n" +
            "rep.CLEARFLAG as clearflag,\n" +
            "if(acc.ACCOUNTSTATUS ='A001','正常',if(acc.ACCOUNTSTATUS='A002','逾期',if(acc.ACCOUNTSTATUS='A003','正常结清',if(acc.ACCOUNTSTATUS='A004','提前结清',if(acc.ACCOUNTSTATUS ='A014','退货结清',if(acc.ACCOUNTSTATUS='A007','委外','其他'))))))as status,\n" +
            "rep.FPERIOD as fperiod,\n" +
            "DATE_FORMAT(rep.FMATUREDAY,'%Y-%m-%d') as fmatureday,\n" +
            "DATE_FORMAT(rep.CLEARDATE,'%Y-%m-%d') as cleardate,\n" +
            "sum(det.FRECEL + det.FEXEMPT)as frecel,\n" +
            "sum(det.freal) as freal,\n" +
            "SUM(if(det.MONEYITEMCODE ='ILATEPENALTY',det.FRECEL + det.FEXEMPT,0)) as ilatepenalty,\n" +
            "SUM(det.FEXEMPT) as fexempt,\n" +
            "(SUM(det.FRECEL-det.FREAL-det.FEXEMPT) )as tobefrecl,\n" +
            "sum(det.FRECEL + det.FEXEMPT)as totalfrecel\n" +
            "FROM t_replant rep\n" +
            "LEFT JOIN t_replantdetail det ON det.PLANTID = rep.PLANTID\n" +
            "LEFT JOIN t_account acc ON acc.ACCOUNTNO = det.ACCOUNTNO\n" +
            " where acc.accountno =#{accountno} \n" +
            "GROUP BY rep.FPERIOD ")
    List<ReplantDTO> getReplantDetail(@Param("accountno") String accountno);

}